-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
GH-143948: Explain graphlib's cycle-finding code #143950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| # On Finding Cycles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # On Finding Cycles | |
| # On Finding Cycles |
| # There is a (at least one) total order if and only if the graph is | ||
| # acyclic. | ||
| # | ||
| # When it is cyclic, "there's a cycle - somewhere!" isn't very helpful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that knowing that there is a cycle could still be useful! so
| # When it is cyclic, "there's a cycle - somewhere!" isn't very helpful. | |
| # When it is cyclic, "there's a cycle - somewhere!" is not always helpful. |
| # | ||
| # When it is cyclic, "there's a cycle - somewhere!" isn't very helpful. | ||
| # In theory, it would be most helpful to partition the graph into | ||
| # strongly connected components (SCCs) and display those with more than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Others could argue that WCCs are also enough for their cases. Do you want to explain the difference?
| # That's a lot of work, though, and we can get most of the benefit much | ||
| # more easily just by showing a single specific cycle. | ||
| # | ||
| # Finding a cycle is most natural via a breadth first search, which can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Finding a cycle is most natural via a breadth first search, which can | |
| # Finding a cycle is most natural via a breadth-first search (BFS), which can |
I am not entirely sure for the dash. I would however mention BFS because readers may be familiar with the abbreviation (I am personally more used to the abbrev than the full word... but this is what happens when you use it a lot).
| # Worst case time is linear in the number of nodes plus the number of | ||
| # edges. Worst case memory burden is linear in the number of nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Worst case time is linear in the number of nodes plus the number of | |
| # edges. Worst case memory burden is linear in the number of nodes. | |
| # If |V| is the number of vertices and |E| is the number of edges, | |
| # worst case time is O(|V| + |E|) and worst case memory burden is O(|V|). |
Strictly speaking this is just the usual complexity of DFS. But I think we can use the same notations as Wikipedia here. Unless you explicitly want to avoid O-notation.
gh-143948: Explain graphlib's cycle-finding code
Long overdue comments explaining what's going on, and why. No code changes, just comments.